/**
 *  WengWeng
 *  Created by wenhao on Jul 30, 2014.
 *  Copyright (c) 2014年 mafengwo. All rights reserved.
 */
package com.f.plusonedemo;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

/**
 * @author wenhao
 *
 */
public class PlusOneAnim {

	private PopupWindow popWindow;
	private TextView textView;
	private LayoutParams layoutParams;
	private android.view.animation.Animation animation;
	
	private Context context;
	private View view;
	private boolean flag;
	public PlusOneAnim(Context c,View v){
		
		context = c;
		view = v;
	}
	
	public PopupWindow init(){
		
		animation = AnimationUtils.loadAnimation(context, R.anim.plus_one_animation);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View layout = inflater.inflate(R.layout.plus_one_layout, null);

		textView = (TextView) layout.findViewById(R.id.plus_one_textview);
		
		popWindow = new PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
		popWindow = new PopupWindow(layout,50,100);
		// 控制popupwindow点击屏幕其他地方消失
		popWindow.setBackgroundDrawable(context.getResources().getDrawable(
				R.drawable.pulus_one_shap_bg));// 设置背景图片，不能在布局中设置，要通过代码来设置
		popWindow.setOutsideTouchable(true);// 触摸popupwindow外部，popupwindow消失。这个要求你的popupwindow要有背景图片才可以成功，如上
		
		return popWindow;
	}
	
	public void show(){
		
		if(flag == false){
			return;
		}
		popWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
		textView.startAnimation(animation);
		textView.postDelayed(new Runnable() {
			public void run() {
				popWindow.dismiss();
			}
		}, 1000);
	}
	
	public void setPlusShowStatus(boolean f){
		flag = f;
	}
}
